package edu.uw.tcss360.group6.gui;

import edu.uw.tcss360.group6.gui.MainCards.*;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayDeque;

/**
 * Created with IntelliJ IDEA.
 * edu.uw.tcss360.group6.model.User: Lemtzas
 * Author: David Sharer
 * Date: 2/20/13
 * Time: 9:01 PM
 * To change this template use File | Settings | File Templates.
 */
@SuppressWarnings("serial")
public class MainPanel extends JPanel {
    private static final int PREFERRED_WIDTH  = 350;
    private static final int PREFERRED_HEIGHT = 500;
    private String my_previous_card;
    private String my_current_card;
    private WeavingDraftPanel my_weaving_draft_panel;
    private JPanel my_weaving_selection_panel;
    private ArrayDeque<String> my_card_history = new ArrayDeque<String>();

    public MainPanel() {
        super(new CardLayout());
        this.setBackground(Color.RED);
        this.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
        this.add(new SplashPanel(), "splash");
        this.add(new LoginPanel(), "login");
        this.add(new RegisterPanel(), "Register");
        this.add(new UserSplashPanel(),"user-splash");
        this.add(new ContestantSplashPanel(),"contestant-splash");
        this.add(new JudgeSplashPanel(),"judge-splash");
        this.add(new OrganizerSplashPanel(),"organizer-splash");
        this.add(new EntryPanel(), "edu.uw.tcss360.group6.model.Entry");
        my_weaving_draft_panel = new WeavingDraftPanel();
        this.add(my_weaving_draft_panel, "weaving-draft");
        my_weaving_selection_panel = new JPanel();
        my_weaving_selection_panel.setBackground(Color.WHITE);
        this.add(my_weaving_selection_panel, "weaving-draft-selection");
        
    }
    public String getCard() {
        return my_current_card;
    }
    public WeavingDraftPanel getWeavingPanel()
    {
    	return my_weaving_draft_panel;
    }
    public JPanel getWeavingSelectionPanel()
    {
    	return my_weaving_selection_panel;
    }
    public void addToWeavingSelectionPanel(JButton the_button)
    {
    	my_weaving_selection_panel.add(the_button);
    }
    public void setCard(final String the_card) {
    	getMy_card_history().push(the_card);
        my_current_card = getMy_card_history().peek();
; //TODO: this will likely not work well, we should come up with a better way. (shuffling the cards?) - David
        CardLayout cl = (CardLayout)(this.getLayout());
        //TODO: CHANGE TopPanel TITLE
        cl.show(this, my_current_card);    
    }

    public void clearCardHistory() {
        my_previous_card = null;
    	getMy_card_history().clear();
    }

    public void gotoPreviousCard() {
        if(my_previous_card != null) {
            this.setCard(getPreviousCard());
        }
    }

    public String getPreviousCard(){
    	if(getMy_card_history().size() > 1){
        getMy_card_history().pop();
        my_current_card = getMy_card_history().pop();
    	my_previous_card = getMy_card_history().peek();
    //	getMy_card_history().push(my_current_card);
    	return my_current_card;
    	}
    	else if(getMy_card_history().size() == 1)
    	{
    		my_current_card = getMy_card_history().pop();
        	my_previous_card = null;
     		return my_current_card;
    	}
    	else 
    	{
    		return my_current_card;
    	}
    }
	public ArrayDeque<String> getMy_card_history() {
		return my_card_history;
	}
	public void setMy_card_history(ArrayDeque<String> my_card_history) {
		this.my_card_history = my_card_history;
	}
}
